class SiteConfiguration < ActiveRecord::Base
  
  validates_uniqueness_of :prop_name
  
  attr_accessible :prop_name, :string_prop_value, :integer_prop_value, :boolean_prop_value, :text_prop_value
  
  
  def self.get_text_prop(prop_name)
    sc = SiteConfiguration.find_by_prop_name(prop_name)
    sc.text_prop_value if sc
  end
  def self.get_boolean_prop(prop_name)
    sc = SiteConfiguration.find_by_prop_name(prop_name)
    sc.boolean_prop_value if sc
  end
  
  def self.get_string_prop(prop_name)
    sc = SiteConfiguration.find_by_prop_name(prop_name)
    sc.string_prop_value if sc
  end
  
  def self.get_integer_prop(prop_name)
    sc = SiteConfiguration.find_by_prop_name(prop_name)
    sc.integer_prop_value if sc
  
  end
  
  
  
  private
  
  #Refactor
  def prop_consistent
    
    #if (!self.string_prop_value or self.string_prop_value.empty?) and (!self.boolean_prop_value) and (!self.integer_prop_value)
    #  errors.add(:prop_name, "One value for the property should be used")
    #end
    
    #only one can be set  
    #if (self.string_prop_value and self.boolean_prop_value) or 
    #  (self.string_prop_value and self.integer_prop_value) or
    #  (self.boolean_prop_value and self.integer_prop_value) or
    #  (self.string_prop_value and self.integer_prop_value and self.boolean_prop_value)
    #  errors.add(:prop_name, "Only one value for the property should be used")
    #end    
  end
end
